<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:c="http://java.sun.com/jsp/jstl/core">
	<ui:composition template="common.xhtml">
        <ui:define name="corpo">
        	<p:dialog id="modalDialog" widgetVar="dlgEdicao" modal="true" dynamic="true" appendToBody="true" showEffect="explode" hideEffect="drop" header="Edição de conserto" >
			 	<h:form id="formEdicaoConserto">
			 		<p:panel id="pnModalConserto" styleClass="panelSemBorda" > 
			 			<h:panelGrid columns="2" cellpadding="3" id="pnEdicao" border="0" >
			    			<ui:include src="/modal_conserto.xhtml" />
			    		</h:panelGrid>
			    	</p:panel>
			    </h:form>
			</p:dialog>
        	<p:dialog id="modalDialogConclusaoConserto" widgetVar="dlgConclusaoConserto" modal="true" dynamic="true" appendToBody="true" showEffect="explode" hideEffect="drop" header="Conclusão de conserto" >
			 	<h:form id="formConclusaoConserto">
			 		<p:panel id="pnModalConclusaoConserto" styleClass="panelSemBorda" > 
			 			<h:panelGrid columns="2" cellpadding="3" id="pnEdicao" border="0" >
			    			<ui:include src="/modal_conclusao_conserto.xhtml" />
			    		</h:panelGrid>
			    	</p:panel>
			    </h:form>
			</p:dialog>
			<p:dialog id="ModalDialogPagamento" widgetVar="dlgModalPagamento" modal="true" dynamic="true" appendToBody="true" showEffect="explode" hideEffect="drop" header="Pagamento" >
			 	<h:form id="formModalPagamento">
			 		<p:panel id="pnModalPagamento" styleClass="panelSemBorda" > 
			 			<h:panelGrid columns="2" cellpadding="3" id="pnEdicao" border="0" >
			    			<ui:include src="/modal_pagamento.xhtml" />
			    		</h:panelGrid>
			    	</p:panel>
			    </h:form>
			</p:dialog>
			<p:confirmDialog id="confirmDialog" message="Deseja realmente excluir o conserto" header="Excluir?" severity="alert" widgetVar="confirmation" appendToBody="true">
           		<h:form id="formExclusao">  
       				<p:commandButton id="confirm" value="Sim" actionListener="#{consertoManagedBean.excluirConserto()}" update=":formPesquisaConsertos:dataTableResultado" oncomplete="confirmation.hide()"  />  
       				<p:commandButton id="decline" value="Não" onclick="confirmation.hide()" type="button" />
       			</h:form>   
   			</p:confirmDialog>
            <h:form id="formPesquisaConsertos" > 
            	<p:messages id="messages" showDetail="true"  autoUpdate="true" closable="true" rendered="true"/>
		        <p:panel id="panelPesquisaConserto" header="Consertos" style="width: 700;">
		        	<h:panelGrid columns="2" cellpadding="2" id="pgPesquisa" border="0" >
		                
		                <h:outputLabel for="inputCpf" value="CPF:"/>
		                <p:inputMask value="#{consertoManagedBean.filtro.cpf}" mask="999.999.999-99"  id="inputCpf" />
		                
		                <h:outputLabel for="inputNome" value="Nome:"/>
		                <h:inputText value="#{consertoManagedBean.filtro.nomeCliente}" maxlength="50" size="50" id="inputNome" />
		                
		                <h:outputLabel for="calDataEntradaInicio" value="Data de entrada:" rendered="#{consertoManagedBean.usuarioLogado.gerente}"/>
		                <h:panelGroup rendered="#{consertoManagedBean.usuarioLogado.gerente}">
		                	<p:calendar id="calDataEntradaInicio" value="#{consertoManagedBean.filtro.dataEntradaInicio}" showOn="button" label="Data entrada inicio"/>
		                	<h:outputLabel value=" a "/>
		                	<p:calendar id="calDataEntradaFim" value="#{consertoManagedBean.filtro.dataEntradaFim}" showOn="button" label="Data entrada fim"/>
		                </h:panelGroup>  
		                
		                <h:outputLabel for="calDataConclusaoInicio" value="Data de conclusão:" rendered="#{consertoManagedBean.usuarioLogado.gerente}"/>
		                <h:panelGroup rendered="#{consertoManagedBean.usuarioLogado.gerente}">
		                	<p:calendar id="calDataConclusaoInicio" value="#{consertoManagedBean.filtro.dataConclusaoInicio}" showOn="button" label="Data conclusão inicio" />
		                	<h:outputLabel value=" a "/>
		                	<p:calendar id="calDataConclusaoFim" value="#{consertoManagedBean.filtro.dataConclusaoFim}" showOn="button" label="Data conclusão fim"/>
		                </h:panelGroup>  
		                
		                <h:outputLabel for="selectPesquisaStatus" value="Status: " />
		                <h:selectOneMenu id="selectPesquisaStatus" value="#{consertoManagedBean.filtro.status}">
			            	<f:selectItems value="#{consertoManagedBean.listaDeStatusDeConsertos}" var="status" itemValue="#{status.codigo}" itemLabel="#{status.descricao}" />
			            </h:selectOneMenu> 
			            
			            <h:outputLabel value=""/>
			            <h:panelGroup>
			                <p:commandButton type="submit" value="Pesquisar" id="btPesquisarConserto" icon="ui-icon-disk" actionListener="#{consertoManagedBean.pesquisaConserto}"  update="dataTableResultado"/>
			                <p:commandButton id="btIncluir"  value="Novo conserto" actionListener="#{consertoManagedBean.novoConserto}"  update=":formEdicaoConserto:pnModalConserto" oncomplete="dlgEdicao.show();" />
			            </h:panelGroup>
		                <h:panelGroup>
		                	<h:outputLabel value="Exportar para:"/>
						    <h:commandLink>
						    	<p:graphicImage value="/img/excel.png" />  
		            			<p:dataExporter type="xls" target="dataTableResultado" fileName="consertos" />  
		        			</h:commandLink>  
							<h:commandLink>  
							    <p:graphicImage value="/img/pdf.png" />  
							    <p:dataExporter type="pdf" target="dataTableResultado" fileName="consertos" />  
							</h:commandLink>
						</h:panelGroup>  
		        	</h:panelGrid>
				</p:panel>
				<h:panelGrid width="100%" >
					<p:dataTable id="dataTableResultado" var="_conserto" value="#{consertoManagedBean.consertos}"
				                 paginator="true" rows="10" 
				                 paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
				                 rowsPerPageTemplate="5,10,15">
				        <f:facet name="header">
				            Resultado da pesquisa
				        </f:facet>
				        
						<p:column style="width:4%" headerText="Ações" exportable="false">
						
							<p:commandButton id="btEditar" 
			            	icon="ui-icon-pencil" 
			            	oncomplete="dlgEdicao.show();" 
							update=":formEdicaoConserto:pnModalConserto"
			            	action="#{consertoManagedBean.selecionaConserto(_conserto)}" />  
			            	<p:tooltip for="btEditar" value="Editar" showEffect="slide" hideEffect="fade" />
			            	
			            	<p:commandButton id="btExcluir" onclick="confirmation.show()" icon="ui-icon-close" rendered="#{!_conserto.concluido}">
			                	<f:setPropertyActionListener value="#{_conserto}" target="#{consertoManagedBean.conserto}" />
			                </p:commandButton> 
			                <p:tooltip for="btExcluir" value="Excluir" showEffect="slide" hideEffect="fade" />
			                
							<p:commandButton id="btConcluirConserto" 
				            	icon="ui-icon-check" 
				            	oncomplete="dlgConclusaoConserto.show();" 
				            	update=":formConclusaoConserto:pnModalConclusaoConserto"
				            	action="#{consertoManagedBean.selecionaConserto(_conserto)}" 
				            	rendered="#{!_conserto.concluido}"
				            	/> 
		                	<p:tooltip for="btConcluirConserto" value="Concluir conserto..." showEffect="slide" hideEffect="fade" />
			               
			                <p:commandButton id="btAbrirModalPagamento" 
			                	icon="ui-icon-cart" 
			                	oncomplete="dlgModalPagamento.show();"  
			                	update=":formConclusaoConserto:pnModalConclusaoConserto"
				            	action="#{consertoManagedBean.selecionaConserto(_conserto)}" 
			                	rendered="#{_conserto.concluido and !_conserto.pago}"
			                	/> 
			                <p:tooltip for="btAbrirModalPagamento" value="Realizar pagamento..." showEffect="slide" hideEffect="fade" />
				        </p:column>    
				        
				         <p:column>
				          	<f:facet name="header">  
					            <h:outputText value="Id" />  
					        </f:facet>  
				        	<h:outputText value="#{_conserto.idConserto}" />
				        </p:column>   
				        
				        <p:column>
				          	<f:facet name="header">  
					            <h:outputText value="Cliente" />  
					        </f:facet>  
				        	<h:outputText value="#{_conserto.cliente.nome}" />
				        </p:column>
				
				        <p:column>
				        	<f:facet name="header">  
					            <h:outputText value="Tipo do produto" />  
					        </f:facet> 
				        	<h:outputText value="#{_conserto.tipoEquipamento}" />
				        </p:column>
				
				        <p:column>
				        	<f:facet name="header">  
					            <h:outputText value="Modelo do produto" />  
					        </f:facet> 
				        	<h:outputText value="#{_conserto.modelo}" />
				        </p:column>
				        
				        <p:column styleClass="alignCenter">
				        	<f:facet name="header">  
					            <h:outputText value="Data de entrada" />  
					        </f:facet> 
				        	<h:outputText value="#{_conserto.dataEntrada}" >
				        	 	<f:convertDateTime pattern="dd/MM/yyyy" />
				        	</h:outputText>
				        </p:column>
				        
				        <p:column styleClass="alignCenter">
				        	<f:facet name="header">  
					            <h:outputText value="Data de previsão" />  
					        </f:facet> 
				        	<h:outputText value="#{_conserto.dataPrevisaoEntrega}">
				        	 	<f:convertDateTime pattern="dd/MM/yyyy" />
				        	</h:outputText>
				        </p:column>
				        
				        <p:column styleClass="alignRight" footerText="#{consertoManagedBean.totalOrcadoFormatted}">
				        	<f:facet name="header">  
					            <h:outputText value="Valor orçado" />  
					        </f:facet> 
				        	<h:outputText value="#{_conserto.valorOrcado}">
				        		<f:convertNumber currencySymbol="R$" type="currency" minFractionDigits="2"/>
				        	</h:outputText>
				        </p:column>
				        
				         <p:column styleClass="alignCenter">
				         	<f:facet name="header">  
					            <h:outputText value="Data de conclusão" />  
					        </f:facet> 
				        	<h:outputText value="#{_conserto.dataConclusao}">
				        	 	<f:convertDateTime pattern="dd/MM/yyyy" />
				        	</h:outputText>
				        </p:column>
				        
				        <p:column styleClass="alignCenter">
				        	<f:facet name="header">  
					            <h:outputText value="Data de retirada" />  
					        </f:facet> 
				        	<h:outputText value="#{_conserto.dataRetirada}">
				        	 	<f:convertDateTime pattern="dd/MM/yyyy" />
				        	</h:outputText>
				        </p:column>
				        
				         <p:column styleClass="alignCenter">
				        	<f:facet name="header">  
					            <h:outputText value="Data de pagamento" />  
					        </f:facet> 
				        	<h:outputText value="#{_conserto.dataPagamento}">
				        	 	<f:convertDateTime pattern="dd/MM/yyyy" />
				        	</h:outputText>
				        </p:column>
				        
				        <p:column styleClass="alignRight" footerText="#{consertoManagedBean.totalPagamentoFormatted}">
				        	<f:facet name="header">  
					            <h:outputText value="Valor pagamento" />  
					        </f:facet> 
				        	<h:outputText value="#{_conserto.valorPagamento}">
				        		<f:convertNumber currencySymbol="R$" type="currency" minFractionDigits="2"/>
				        	</h:outputText>
				        </p:column>
				        
				        
				    </p:dataTable>
				 </h:panelGrid>
			</h:form>
                    
	       
        </ui:define>
    </ui:composition>
</html>